const app = getApp();
Page({
  data: {
    picServer: 'http://appapp.b0.upaiyun.com',
    pageno: 1,
    renderObj: {
      listArr: [],
    },
    pageCount: '',
  },
  onLoad: function () {
    this.initPage();
  },
  initPage: function () {
    var _this = this;
    app.doReq(app.globalData.SERVICE.USERCENTER.MYALBUMLIST, {
      id: app.globalData.userid,
      pageno: this.data.pageno,
      pagesize: 10,
      type: 1
    }, 'get', function (res) {
      if (_this.data.pageno == 1) {
        _this.setData({
          renderObj: {
            listArr: res.data.pageitems,
          },
          pageCount: res.data.pagecount
        })
      } else {
        _this.setData({
          renderObj: {
            listArr: _this.data.renderObj.listArr.concat(res.data.pageitems)
          },
        });
      }
    });
  },
  doDel: function (e) {
    var _this = this;
    var id = app.getBindDataSet(e).id;
    app.confirm("提示", "确定删除？").then(function (value) {
      if (value) {
        app.doReq(app.globalData.SERVICE.USERCENTER.ALBUMDEL, {
          "xgmember.id": app.globalData.userid,
          "id": id
        }, 'get', function (res) {
          if (res.data.code == 200) {
            wx.showToast({
              title: res.data.errmsg,
              icon: 'success'
            });
            _this.setData({
              renderObj: {
                listArr: [],
              },
              pageno: 1,
              pageCount: ''
            })
            _this.initPage();
          }
        })
      }
    });
  },
  onReachBottom: function () {//刷新
    var _this = this;
    var currentPageNo = _this.data.pageno;
    if (currentPageNo <= _this.data.pageCount) {
      _this.data.pageno++;
      _this.initPage({});
    }
  },
  doUpload: function () {
    var _this=this;
    wx.chooseVideo({
      count: 1,
      success: function (res) {
       
        var tempFilePath = res.tempFilePath;//文件临时访问路径
        var thumbTempFilePath = res.thumbTempFilePath;//文件临时存储对象
        wx.showLoading({
          title: '上传中。。。',
          mask:true
        })
        wx.uploadFile({
          url: app.globalData.SERVICE.USERCENTER.IMGUPLOAD+"?type=1",
          filePath: tempFilePath,
          name: 'imgFile',
          success: function (res) {
            wx.hideLoading();
            console.log(res)
            var data = res.data
            if (typeof (data) == 'string') {
              data = JSON.parse(data);
            }
            //do something
            if (data.error == 0) {//代表上传成功
              var url = data.url;//上传路径
              var title = data.title;
            
              app.doReq(app.globalData.SERVICE.USERCENTER.IMGTOSERVER, {
                'memberAlbum.memId': app.globalData.userid,
                'memberAlbum.annex.id': title
              }, 'get', function (res) {
             
                if (res.data.code == 200) {
                  wx.showToast({
                    title: '上传成功',
                    icon: 'success'
                  });
                  _this.setData({
                    renderObj: {
                      listArr: [],
                    },
                    pageno: 1,
                    pageCount: ''
                  },function(){
                    _this.initPage();
                  })
                 
                }
              });
            }
          }
        })
      },
    })
  }
})